package org.liveboardgames.common.util;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.HashMap;
import java.util.Map;

public class ExternalMap extends HashMap implements IExternalMap {

  private static final long serialVersionUID = 1L;

  public ExternalMap() {
    super();
  }

  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    Map map = (Map)in.readObject();
    if (map != null) {
      for (Object key : map.keySet()) {
        this.put(key, map.get(key));
      }
    }
    // throw new IOException("Not handled yet");
  }

  public void writeExternal(ObjectOutput out) throws IOException {
    Map map = new HashMap();
    for (Object object : this.keySet()) {
      map.put(object, this.get(object));
    }
    out.writeObject(map);
  }
}
